require(['/js/config.js'],()=>{
    require(['template','url','swiper','header','footer','protect'],(template,url,Swiper)=>{
        class Mall{
            constructor(){
                this.resp=[]
                this.getAllList().then(()=>{
                    this.showMore()
                    
                })
                this.banner()
                
            }
            getGoodsList1(){
                $.get('/libs/json/malllist1.json',resp=>{
                    $('#BlackShark3-content').html(template('blackshark3template',{list:resp}))
                })
            }
            getGoodsList2(){
                $.get('/libs/json/malllist2.json',resp=>{
                    $('#blackshark3pro-content').html(template('blackshark3protemplate',{list:resp}))
                })
            }
            getGoodsList3(){
                $.get(url.rap2+'/libs/json/malllist3',resp=>{
                    this.resp.push(resp)
                    if(resp.code===200){
                        const { list }=resp.body
                        $('#supporters-content').html(template('suppoterstemplate',{list}))
                    }
                })
            }
            getGoodsList4(){
                $.get(url.rap2+'/libs/json/malllist4',resp=>{
                    this.resp.push(resp)
                    if(resp.code===200){
                        const { list }=resp.body
                        $('#case-content').html(template('casetemplate',{list}))
                    }
                })
            }
            getGoodsList5(){
                $.get(url.rap2+'/libs/json/malllist4',resp=>{
                    this.resp.push(resp)
                    if(resp.code===200){
                        const { list }=resp.body
                        $('#headphones-content').html(template('headphonestemplate',{list}))
                    }
                })
            }
            getAllList(){
                return new Promise(resolve=>{
                    this.getGoodsList1()
                    this.getGoodsList2()
                    this.getGoodsList3()
                    this.getGoodsList4()
                    this.getGoodsList5()
                    this.orderUpBtn(this.resp)
                    this.orderDownBtn(this.resp)
                    resolve()
                })
                
            }
            showMore(){
                $('.viewMore').on('click',function(){
                   $(this).prev().prev().css('height','auto')
                   $(this).css('display','none')
                })
            }
            banner(){
                new Swiper ('.swiper-container', {
                    loop: true, // 循环模式选项
                    
                    // 如果需要分页器
                    pagination: {
                      el: '.swiper-pagination',
                    },
                    
                    // 如果需要前进后退按钮
                    navigation: {
                      nextEl: '.swiper-button-next',
                      prevEl: '.swiper-button-prev',
                    },
                    
                    autoplay: {
                        delay: 2000,
                        stopOnLastSlide: false,
                        disableOnInteraction: true,
                    }
                    
                  })    
            }
            orderUpBtn(resplist){
                $('.orderUp').on('click',function(){
                    const id =$(this).data('id')
                    const {list}=resplist[id].body
                    for(var i =0;i<list.length-1;i++){
                        for(var j =0;j<list.length-i-1;j++){
                            if(list[j].price>list[j+1].price){
                                var temp = list[j]
                                list[j]=list[j+1]
                                list[j+1]=temp
                            }
                        }
                    }
                    switch (id) {
                        case 0:
                            $('#supporters-content').html(template('suppoterstemplate',{list}));
                            break;
                        case 1:
                            $('#case-content').html(template('casetemplate',{list}))
                            break;
                        case 2:
                            $('#headphones-content').html(template('headphonestemplate',{list}))
                            break;
                        }
                })
            }
            orderDownBtn(resplist){
                $('.orderDown').on('click',function(){
                    const id =$(this).data('id')
                    const {list}=resplist[id].body
                    for(var i =0;i<list.length-1;i++){
                        for(var j =0;j<list.length-i-1;j++){
                            if(list[j].price<list[j+1].price){
                                var temp = list[j]
                                list[j]=list[j+1]
                                list[j+1]=temp
                            }
                        }
                    }
                    switch (id) {
                        case 0:
                            $('#supporters-content').html(template('suppoterstemplate',{list}));
                            break;
                        case 1:
                            $('#case-content').html(template('casetemplate',{list}))
                            break;
                        case 2:
                            $('#headphones-content').html(template('headphonestemplate',{list}))
                            break;
                        }
                })
            }
        }
        new Mall()
    })
})